How can I run two commands in one line in Windows CMD?
How can I run two commands in one line in Windows CMD?
31614-Jul-2023
Updated on 15-Jul-2023
Home / DeveloperSection / Forums / How can I run two commands in one line in Windows CMD?
How can I run two commands in one line in Windows CMD?
Aryan Kumar
15-Jul-2023Sure, there are two ways to run two commands in one line in Windows CMD:
The ampersand (&) is a special character that can be used to run two commands in one line. When the ampersand is used, CMD will run the first command, and then the second command.
For example, to run the
dir
command and theecho
command in one line, you would use the following command:This will first run the
dir
command, which will list the contents of the current directory. Then, theecho
command will be run, which will display the text "This is the second command."The semicolon (;) is another special character that can be used to run two commands in one line. When the semicolon is used, CMD will run the first command, and then the second command, but only if the first command is successful.
For example, to run the
dir
command and theecho
command in one line, but only if thedir
command is successful, you would use the following command:This will first run the
dir
command. If thedir
command is successful, theecho
command will be run. However, if thedir
command is not successful, theecho
command will not be run.